<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/bootstrap.min.css"/>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/js/layui/css/layui.css"/>
    <script src="${pageContext.request.contextPath}/js/jquery.min.js"></script>
    <script src="${pageContext.request.contextPath}/js/bootstrap.min.js"></script>
    <script src="${pageContext.request.contextPath}/js/DatePicker.js"></script>
    <title>商品添加页面</title>
</head>
<body>
<script type="text/javascript">
	$.get("${pageContext.request.contextPath}/goodstypeservlet?method=goodstypelist",(resp) => {
	    const {code,msg,data} = resp;
	    if(code === 200){
	        setMsg(data);
        }else{
	        alert(msg)
        }
    });
	let setMsg = (data) => {
	    $("#type").html("");
	    data.map((obj)=>{
	        let opt = new Option(obj.name,obj.id);
            $("#type").append(opt);
        })
    }
</script>
<div class="row" style="margin-left: 20px;">
    <form action="${pageContext.request.contextPath }/addGoods?method=add" method="post" enctype="multipart/form-data">
        <div>
            <h3>新增商品 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: red;font-size: 15px">${msg}</span></h3>
        </div>
        <hr/>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group form-inline">
                    <label>名称:</label>
                    <input type="text" name="name" required class="form-control" placeholder="商品名" value="${name}"/>
                </div>

                <div class="form-group form-inline">
                    <label>分类:</label>
                    <select name="typeid" class="form-control" id="type">

                    </select>
                </div>
                <div class="form-group form-inline">
                    <label>时间:</label>
                    <input type="text" name="pubdate"
                           class="layui-input form-control"
                           id="test1" placeholder="时间" required
                           style="height: 34px;border-radius: 5px;border: 1px solid #ccc;cursor: pointer">
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group form-inline">
                    <label>价格:</label>
                    <input type="text" name="price" required placeholder="价格" value="${price}" class="form-control"/>
                </div>
                <div class="form-group form-inline">
                    <label>评分:</label>
                    <input type="text" name="star" required placeholder="评分" value="${star}" class="form-control"/>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-10">
                <div class="form-group form-inline">
                    <label>商品图片</label>
                    <input type="file" name="picture"/>
                </div>
                <div class="form-group ">
                    <label>商品简介</label>
                    <textarea name="intro" required class="form-control" rows="5">${intro}</textarea>
                </div>
                <div class="form-group form-inline text-center">
                    <input type="submit" value="添加" class="btn btn-primary"/>
                    <input type="reset" value="重置" class="btn btn-default"/>
                </div>
            </div>
        </div>
    </form>
</div>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/layui/layui.js"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述 JS 路径需要改成你本地的 -->
<script>
    layui.use('laydate', function() {
        var laydate = layui.laydate;

        //常规用法
        laydate.render({
            elem: '#test1'
        });
    });
</script>
</body>
</html>